//
//  AnimationScopePageView.swift
//  SwiftUIDemo
//
//  Created by zhouzuosong on 2020/8/31.
//  Copyright © 2020 Kael. All rights reserved.
//

import SwiftUI

struct HilightButtonStyle: ButtonStyle {

    func makeBody(configuration: Self.Configuration) -> some View {
        configuration.label
            .padding()
            .foregroundColor(configuration.isPressed ? .green : .white)
            .background(configuration.isPressed ? Color.red : Color.blue)
            .cornerRadius(8.0)
      }
    
}

struct AnimationScopePageView: View {
    @State var changeScale = false
    @State var unlock = false

    var body: some View {
        VStack {
            BannerText(pageTitle: "Animation Parameter", text: "设置每个属性", backgroundColor: Color.pink)
            
            Button(action: {
                self.unlock = true
            }, label: {
                Text("Action")
            })
            .buttonStyle(HilightButtonStyle())
            
            Button(action: {
                self.changeScale.toggle()
            }, label: {
                Text("Action!")
            })
            .padding()
            
            HStack(spacing: 10){
                Rectangle()
                    .fill(Color.blue)
                    .frame(height: 200)
                
                VStack(spacing: 10){
                    
                    Rectangle()
                        .fill(Color.blue)
                        .frame(width: 120)
                    Rectangle()
                        .fill(changeScale ? Color.red : Color.blue)
                        .frame(width: changeScale ? 180 : 120, height: changeScale ? 120 : 60)
//                        .scaleEffect(changeScale ? 2 : 1)
                        .animation(.easeIn)
                    Rectangle()
                        .fill(Color.blue)
                        .frame(width: 120)

                }
//                .animation(.easeIn)

                Rectangle()
                    .fill(Color.blue)
                    .frame(height: 200)

            }
            .frame(height: 200)
            .animation(.easeIn)

            Spacer()

        }
    }
}

struct AnimationScopePageView_Previews: PreviewProvider {
    static var previews: some View {
        AnimationScopePageView()
    }
}
